<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String operation = request.getParameter("operation");
%>
<%@ page import="com.starbaba.core.web.constant.WebConstants"%>
<%@ page import="com.starbaba.system.user.model.UserVO"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="/common/common-css.jsp"%>
<style>
.table>th {
	vertical-align: center;
	background-color: grey;
}

input[type="radio"] {
	font-size: 100px;
	vertical-align: middle;
	margin-top: -2px;
	margin-left: 2px;
	margin-bottom: 1px;
}

.checkbox input[type=checkbox], .checkbox-inline input[type=checkbox],
	.radio input[type=radio], .radio-inline input[type=radio] {
	position: relative;
	margin-left: 1px;
}
</style>
</head>
<body class="no-skin">
	<div class="page-content">
		<div class="page-content-area">
			<div class="row">
				<div class="col-xs-18 col-sm-18 widget-container-col">
					<div class="widget-box widget-color-blue" style="height: 1100px;">
						<!-- #section:custom/widget-box.options.collapsed -->
						<div class="widget-header widget-header-small">
							<h6 class="widget-title lighter">
								<i class="ace-icon glyphicon glyphicon-th-list"></i>活动信息编辑
							</h6>
							<div class="widget-toolbar no-border">
								<a href="#" data-action="collapse"> <i
									class="ace-icon fa fa-chevron-up"></i>
								</a>
							</div>
						</div>

						<div class="widget-body">
							<div class="widget-main" >
								<form class="form-horizontal" id="product-form"
									name="product-form" method="post" enctype="multipart/form-data">
									<input type="hidden" name="id" id="id" placeholder=""
										class="col-xs-12 col-sm-6" value="${paramsMap.model.id}">
									<input type="hidden" name="status" id="status" placeholder=""
										class="col-xs-12 col-sm-6" value="${paramsMap.model.status}">
									<input type="hidden" name="operator"
										value="<%=((UserVO) session.getAttribute(WebConstants.SESSION_ATTRIBUTE_USER)).getUsername()%>" />
									<div>
										<div style="text-align: left">
											<label for="from">平台</label><br> <select name="platform">
												<option value="0">通用</option>
												<option value="1"
													<s:if test="paramsMap.model.platform == 1">selected</s:if>>android</option>
												<option value="2"
													<s:if test="paramsMap.model.platform == 2">selected</s:if>>ios</option>
											</select>
										</div>
										<br>
										<div style="text-align: left">
											<label style="text-align: right">产品</label> <br> <select
												name="prdid"  id="prdid"  class="form-control open_multiselect"
												multiple="multiple">
												<option value="0">通用</option>
												<c:forEach var="item" items="${paramsMap.productList}">
													<option value="${item.code }">${item.kindname }</option>
												</c:forEach>
											</select>
										</div>
										<br>
										<div style="text-align: left">
											<label style="text-align: right">渠道</label><br> <select
												name="channel"  id="channel"   class="form-control open_multiselect"
												multiple="multiple">
												<c:forEach var="item" items="${paramsMap.modelList}">
													<option value="${item.channel_code }">${item.channel_name }</option>
												</c:forEach>
											</select>
										</div>
										<br>
										<div style="text-align: left">
											<label style="text-align: right">不包含渠道</label><br> <select
												name="exclude_channel"  id="exclude_channel" class="form-control open_multiselect"
												multiple="multiple">
												<c:forEach var="item" items="${paramsMap.modelList}">
													<option value="${item.channel_code }">${item.channel_name }</option>
												</c:forEach>
											</select>
										</div>
										<br>
										<div style="text-align: left">
											<label for="from">广告位</label><br> 
											<select name="advert_space">
												<c:forEach items="${paramsMap.advertises}" var="advertise">
													<option value="${advertise.code}" <c:if test="${paramsMap.model.advert_space == advertise.code}">selected=selected</c:if>>${advertise.name}</option>
												</c:forEach> 
											</select>
										</div>
										<br>
										<div style="text-align: left">
											<label for="from">跳转类型</label><br> <select
												name="redirect_type">
												<option value="1"
													<s:if test="paramsMap.model.redirect_type == 1">selected</s:if>>详情页</option>
												<option value="2"
													<s:if test="paramsMap.model.redirect_type == 2">selected</s:if>>API资料页(需要在活动内容设置API序号)</option>
												<option value="3"
													<s:if test="paramsMap.model.redirect_type == 3">selected</s:if>>结果页</option>
												<option value="4"
													<s:if test="paramsMap.model.redirect_type == 4">selected</s:if>>合作方H5页</option>
												<option value="5"
													<s:if test="paramsMap.model.redirect_type == 5">selected</s:if>>车主信用卡</option>
												<option value="6"
													<s:if test="paramsMap.model.redirect_type == 6">selected</s:if>>借条(需要在活动内容设置借条id)</option>													
												<option value="8"
													<s:if test="paramsMap.model.redirect_type == 8">selected</s:if>>联登(需要在活动内容设置联登序号)</option>													
											</select>
										</div>
										<br>
										<div>
											<label for="from">活动名称</label><br>
											<%-- <input type="text"
												name="activity_name" id="activity_name" placeholder=""
												class="col-xs-12 col-sm-12"
												value="${paramsMap.model.activity_name}"> --%>
											<s:select name="activity_id"
												value="%{paramsMap.model.activity_id}"
												list="%{paramsMap.activityList}" listKey="id"
												listValue="name" cssClass="form-control"></s:select>
										</div>
										<br>
										<div>
											<label for="from">位置</label><br> <input type="text"
												name="position" id="position" placeholder=""
												class="col-xs-12 col-sm-12"
												value="${paramsMap.model.position}">
										</div>
										<br>
										<div>
											<label for="from">活动标签(多个,分开)</label><br> <input
												type="text" name="tag" id="tag" placeholder=""
												class="col-xs-12 col-sm-12" value="${paramsMap.model.tag}">
										</div>
										<br>
										<div>
											<label for="from">指定上线时间</label><br>
											<input type="text" class="date-picker input-sm form-control"
												style="padding-left: 0px" id="startTime" name="startTime"
												value="${paramsMap.model.startTime}">
										</div>
										<br>
										<div>
											<label for="from">指定下线时间</label><br>
											<input type="text" class="date-picker input-sm form-control"
												style="padding-left: 0px" id="endTime" name="endTime"
												value="${paramsMap.model.endTime}">
										</div>
										<br>
										<div>
											<label for="from">每天上线时间</label><br>
											<input type="text" class="date-picker-time input-sm form-control"
												style="padding-left: 0px" name="fixed_start_time" 
												value="${paramsMap.model.fixed_start_time}">
										</div>
										<br>
										<div>
											<label for="from">每天下线时间</label><br>
											<input type="text" class="date-picker-time input-sm form-control"
												style="padding-left: 0px" name="fixed_end_time"
												value="${paramsMap.model.fixed_end_time}">
										</div>
										<br>
										<div>
											<label for="from">每日控量上限</label><br> <input type="text"
												name="upper_limit" id="upper_limit" placeholder=""
												class="col-xs-12 col-sm-12"
												value="${paramsMap.model.upper_limit}">
										</div>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="clearfix form-actions">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn  btn-inverse  no-border " onclick="doCancle()"
						id="delete">
						<i class="ace-icon fa fa-undo bigger-160"></i> 取消
					</button>
					&nbsp; &nbsp; &nbsp;
					<button id="btn-save" name="btn-save"
						class="btn  btn-success  no-border" type="button"
						onclick="doSave()">
						<i class="ace-icon fa fa-floppy-o bigger-160"></i> 保存
					</button>
				</div>
			</div>
		</div>
	</div>
	<!--模态框-->
	<div class="modal fade" id="Modal">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title"></h4>
				</div>
				<div class="modal-body clearfix">
					<form id="addImage" name="addImage" method="post"
						enctype="multipart/form-data">
						<div class="row">
							<div class="form-group col-xs-12">
								<div class="input-group col-sm-12">
									<input type="file" class="form-control" name="myFile"
										accept=".png,.jpg,.jpeg" />
								</div>
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" disabled id="confirm">上传</button>
				</div>
			</div>
		</div>
	</div>

	<%@ include file="/common/common-js.jsp"%>
	<%@ include file="/discovery/maxlength.jsp"%>
	<script type="text/javascript" src="${ctx}/ace/js/maxlength.js"></script>
	<script type="text/javascript" src="${ctx}/js/wangEditor-1.3.11.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/jquery.form.js"></script>
	<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
	<script>
		var $multiple = 1;
		var $selector = '';
		var $input = '';

		$(function() {
			$('#img').change(function() {
				var file = this.files[0];
				var r = new FileReader();
				r.readAsDataURL(file);
				$(r).load(function() {
					$('#thumbnail').attr('src', this.result);
					$('#img').attr("value", this.result);
				});
			});

			//点击按钮
			$('.get-img-modal').on('click', function() {
				//展示模态框
				var $this = $(this);
				var $title = $this.attr('data-title');
				$input = $this.attr('data-input');
				$selector = $this.attr('data-selector');
				$multiple = $this.attr('data-multiple');
				if ($multiple == 1) {
					$('input[name="myFile"]').prop('multiple', true);
				} else {
					$('input[name="myFile"]').prop('multiple', false);
				}
				$('#Modal').find('h4.modal-title').html($title);
				$('#Modal').modal('show');
				return false;
			});

			$('.thumbnail').on('click', function() {
				$('#thumbnail').attr('src', "");
				$("input[id=thumbnail]").val("");
			});

			//上传按钮
			$('#confirm').bind('click', function() {
				if ($('input[name="myFile"]').val() != '') {
					uploadImage('#addImage', $selector, $input, $multiple);
				}
				return false;
			});

			$('input[name="myFile"]').on('change', function() {
				if ($(this).val() != '') {
					$('#confirm').prop('disabled', false);
				} else {
					$('#confirm').prop('disabled', true);
				}
			});
		});

		function uploadImage(form, selector, input, multiple) {
			var options = {
				url : "${ctx}/mall/fileupload/fileUpload.action",
				type : "POST",
				dataType : "json",
				beforeSend : function() {
					$(".load_bg,.load_img").show();
				},
				success : function(data) {
					console.log(data);
					var inputValue = '';
					var dataList = data.split('#');
					insertHtml(dataList, selector, multiple);
					if (multiple == 1) {
						//获取真实input的值
						inputValue = $(input).val();
					}

					if (inputValue == '' || inputValue == null) {
						$(input).val(data);
					} else {
						$(input).val(inputValue + '#' + data);
					}

					//隐藏模态框
					$('#Modal').modal('hide');
					//清空modal里面的input的值
					$('input[name="myFile"]').val('');
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert(textStatus);
				},
				complete : function() {
					$(".load_bg,.load_img").hide();
				}
			}
			$('form[name="addImage"]').ajaxSubmit(options);
		}

		function insertHtml(dataList, selector, multiple) {
			var html = '';
			var iconClass = '';
			if (multiple == 0) {
				iconClass = 'change-btntext'
			}
			$.each(dataList, function(index, item) {
				html += '<div class="img-box">' + '<img src="' + item + '"/>'
						+ '<i class="fa fa-times ' + iconClass + '"></i>'
						+ '</div>';
			});
			if (multiple == 1) {
				$(selector).children('.view').removeClass('no-border').append(
						html);
			} else {
				$(selector).children('.view').removeClass('no-border').html(
						html);
			}
		}

		function doCancle() {
			try {
				if (parent) {
					parent.parent['__extdialog_active'].dialog('close');
				}
			} catch (e) {
				window.history.back();
			}
		}

		function doSave() {
			if (isNaN($("#position").val())) {
				parent.bootbox.alert("位置只能为数字");
				return;
			}
			/* if ($.isBlank($("#activity_name").val())) {
				parent.bootbox.alert("产品名称不能为空!");
				return;
			} */
			/* if ($.isBlank($("#startTime").val())) {
				parent.bootbox.alert("上线时间不能为空!");
				return;
			}
			if ($.isBlank($("#endTime").val())) {
				parent.bootbox.alert("下线时间不能为空!");
				return;
			} */
			saveForm();
		}

		function saveForm() {
			var saveUrl = ctx + "/activityCommend/save.action";
			var options = {
				url : saveUrl,
				type : "POST",
				dataType : "json",
				beforeSend : function() {
					$(".load_bg,.load_img").show();
				},
				success : function(data) {
					alert(data["result"]["msg"]);
					parent.parent['__extdialog_active'].dialog('close');
					parent.query_any();
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert(textStatus);
					console.log(XMLHttpRequest, textStatus, errorThrown);
				},
				complete : function() {
					$(".load_bg,.load_img").hide();
				}
			};
			$('form[name="product-form"]').ajaxSubmit(options);
		}

		//时间控件
		jQuery(function($) {
			$(".date-picker").datetimepicker({autoclose:true}).next().on(ace.click_event, function(){
						$(this).prev().focus();
			});
			$(".date-picker-time").datetimepicker({
				autoclose:true,
				format : "hh:ii:ss"
				}).next().on(ace.click_event, function(){
				$(this).prev().focus();
	});
		});


		function echo_multiple(selectObjectId, paramsArray){
			//下拉框的对象
			var object = $("#" + selectObjectId);
			if(paramsArray != ''){
				//遍历回显的数据数组
				object.multiselect('select', paramsArray);
				// $.each(paramsArray,function(index,element){
				// 	object.multiselect('select', element);
				// });
			}
		}

		window.onload=function(){
			var prdid_list = [${paramsMap.model.prdid}];
			// prdid_list = prdid_list.split(',');

			var channel_list = [${paramsMap.model.channel}];
			// channel_list = channel_list.split(',');

			var exclude_channel_list = [${paramsMap.model.exclude_channel}];
			// exclude_channel_list = exclude_channel_list.split(',');

			echo_multiple('prdid',prdid_list);
			echo_multiple('channel',channel_list);
			echo_multiple('exclude_channel',exclude_channel_list);
			$("select[name='activity_id']").combobox();
		}
		
	</script>
</body>
</html>
